Skip to content

Conversation

@AtharvUrunkar
Copy link

This PR fixes a bug where making a HEAD request through Spring’s RestClient fails when the response contains:

Content-Encoding: gzip

An empty body (Content-Length: 0)

Previously, Spring attempted to wrap the empty body in a GZIPInputStream, causing an exception.

Fix implemented

Skip gzip/deflate decompression when:

The HTTP method is HEAD

OR the response declares Content-Length: 0

This prevents GZIPInputStream from being created for empty bodies.

Tests

Added a new test:

headRequestWithGzipContentEncodingShouldNotFail

This test verifies that gzip headers on a HEAD response with an empty body no longer cause exceptions.

Linked issue

Fixes: https://github.com/spring-projects/spring-framework/issues/35966

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 5, 2025
…ring-projects#35966)

Skip gzip decompression when the response has Content-Length: 0 or HEAD method, preventing GZIPInputStream errors on empty bodies.

Add test ensuring HEAD + gzip + empty body does not throw.

Signed-off-by: AtharvUrunkar <[email protected]>
@bclozel bclozel self-assigned this Dec 5, 2025
@bclozel
Copy link
Member

bclozel commented Dec 8, 2025

Thanks for the proposal @AtharvUrunkar but I went with a different approach in 12c3dc0. Cheers!

@bclozel bclozel closed this Dec 8, 2025
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants